package com.woniuxy.consumer;

import com.rabbitmq.client.Channel;
import com.woniuxy.entity.OrderItems;
import com.woniuxy.mapper.OrdersMapper;
import com.woniuxy.util.RabbitMQConst;
import com.woniuxy.util.RabbitMQMessageHelper;
import org.springframework.amqp.core.Message;
import org.springframework.amqp.rabbit.annotation.RabbitListener;
import org.springframework.stereotype.Component;

import javax.annotation.Resource;
import java.util.List;

@Component
public class TopicConsumer {
    @Resource
    private OrdersMapper ordersMapper;

    @RabbitListener(queues = RabbitMQConst.ADD_ORDER_ITEM_LIST_QUEUE)
    public void receiveAddOrderItemListMessage(List<OrderItems> orderItemsList, Channel channel, Message message) {
        RabbitMQMessageHelper.processMessageWithAck(channel, message, msg -> {
            ordersMapper.insertBatchOrderItems(orderItemsList);
        });
    }
}
